package roborally.conditionCombiners;
import java.util.ArrayList;
import java.util.List;

import roborally.*;
import roborally.Statement;
import roborally.Conditions.*;
import roborally.Commands.*;

/**
 * A class of Or-conditions for playing the roborally game, involving a list of conditions.
 * 
 * @version  2.90
 * @author   Michiel Ruelens & Dieter Naten
 */
public class Or extends ConditionCombiner {
	
	private final List<Statement> conditionList;
	
	/**
	 * Creates a new combined condition that returns true if and only if one of the given conditions in the list are true.
	 */
	public Or(List<Statement> conditionList){
		assert(conditionList.size()>=2);
		for(Statement s: conditionList){
			assert(s instanceof Condition || s instanceof ConditionCombiner);
		}
		this.conditionList = new ArrayList<Statement>(conditionList);
		
		//Create a string representation
		this.setStringForm("or");
		for(Statement c: conditionList){
			this.setStringForm(this.getStringForm()+" ("+c.getStringForm()+")");
		}
	}
	
	/**
	 * Validate this combined condition. This method will return true if at least one of the conditions in conditionList are true.
	 */
	@Override
	public boolean validate(Placeable placeable){
		boolean result = false;
		for(Statement c : conditionList){
			if(c.validate(placeable)==true){
				result = true;
			}
		}
		return result;
	}

}
